<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8"/>
	<meta name="keywords" content="cot, command"/>
	<link rel="stylesheet" href="../../Shared/sty/standard.css"/>
	<script defer src="../../Shared/js/toc.js"></script>
	
	<title>Work with cot command in CotEditor on Mac</title>
</head>

<body>
<a name="about_cot"></a>

<h1>Work with cot command in CotEditor on Mac</h1>

<p>CotEditor provides the <code>cot</code> command-line tool, which lets you open documents, receive text through standard input, and control CotEditor directly from the command line. To use the <code>cot</code> command, install it on your computer first.</p>


<section>
<h2>Install the <code>cot</code> command</h2>

<p>You can install the <code>cot</code> command-line tool by creating a symbolic link in Terminal. The actual executable is built in CotEditor at <code>Contents/SharedSupport/bin/cot</code>. If you don’t have a preferred location, placing the symbolic link in <code>/usr/local/bin/</code> is recommended.</p>

<p>To create the symbolic link at the recommended location, run the following commands in Terminal:</p>

<pre class="source"><code>mkdir /usr/local/bin/
ln -s /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /usr/local/bin/cot</code></pre>


<h3>Security authorization</h3>
<p>macOS requires user authorization when an external application invokes CotEditor through the <code>cot</code> command. Normally, authorization is requested the first time you run the <code>cot</code> command. In some cases, however, you may need to authorize it manually in System Settings &gt; Privacy &amp; Security &gt; Automation. Turn on CotEditor under your client application, such as Terminal. For the <code>--wait</code> option, you may also need to turn on System Events.</p>


<h3>Install Python 3</h3>
<p>The <code>cot</code> command is implemented in Python 3. Since macOS 12.3, Python is no longer bundled with macOS, so you need to install <code>python3</code> manually for the cot command.</p>
<p>Installing Apple’s Command Line Developer Tools provides <code>python3</code>. Run the following command in Terminal to install the tools. You can also install <code>python3</code> using any other method.</p>

<pre class="source"><code>xcode-select --install</code></pre>
</section>


<section>
<h2>Uninstall the <code>cot</code> command</h2>

<p>To uninstall the <code>cot</code> command from the recommended location, run the following command in Terminal:</p>

<pre class="source"><code>unlink /usr/local/bin/cot</code></pre>
</section>


<section>
<h2>Use the command with options</h2>

<p>The <code>cot</code> command supports the following options:</p>

<table>
	<thead>
		<tr><th>Option</th><th>Description</th></tr>
	</thead>
	<tbody>
		<tr><th><code>-w</code>, <code>--wait</code></th><td>Wait for the opened document to be closed before returning to the prompt.</td></tr>
		<tr><th><code>-r</code>, <code>--readonly</code></th><td>Open documents as <a href="howto_readonly.html">read-only</a>.</td></tr>
		<tr><th><code>-n</code>, <code>--new</code></th><td>Create a new blank document.</td></tr>
		<tr><th><code>-s</code>, <code>--syntax</code></th><td>Set a specific syntax for the opened document.</td></tr>
		<tr><th><code>-l</code>, <code>--line</code> <code>&lt;line&gt;</code></th><td>Jump to a specific line in the opened document. <code>&lt;line&gt;</code> is an integer specifying the line</td></tr>
		<tr><th><code>-c</code>, <code>--column</code> <code>&lt;column&gt;</code></th><td>Jump to a specific column in the opened document. <code>&lt;column&gt;</code> is an integer specifying the column</td></tr>
		<tr><th><code>-b</code>, <code>--background</code></th><td>Do not bring the application to the foreground.</td></tr>
		<tr><th><code>-h</code>, <code>--help</code></th><td>Show help.</td></tr>
		<tr><th><code>-v</code>, <code>--version</code></th><td>Print version information.</td></tr>
	</tbody>
</table>

<p>For the <code>--line</code> and <code>--column</code> options, you can specify a negative number to count from the end of the document (<code>--line</code>) or from the end of a line (<code>--column</code>).</p>
</section>


<section>
<h2>Execute the <code>cot</code> command</h2>

<p>A simple <code>cot</code> command launches CotEditor, or activates it if CotEditor is already running.</p>

<pre class="source"><code>cot</code></pre>

<p>The following command opens the foo.txt file in CotEditor and moves the insertion point to line 200. The <code>cot</code> command does nothing if foo.txt doesn’t exist.</p>

<pre class="source"><code>cot --line 200 foo.txt</code></pre>

<p>The following command opens the foo.txt file in CotEditor and moves the insertion point to the end of the document:</p>

<pre class="source"><code>cot --line -1 --column -1 foo.txt</code></pre>

<p>Passing a dash (<code>-</code>) in place of a filename enters a mode to receive standard input. The text received is opened as a new document.</p>

<pre class="source"><code>cot -</code></pre>

<p>You can also pipe text. CotEditor opens a new document with the piped text.</p>

<pre class="source"><code>echo "I am a dog but also a cow at the same time." | cot</code></pre>

<p>Using the <code>--wait</code> option, CotEditor can be used as the editor for <code>git</code>.</p>

<pre class="source"><code>git config --global core.editor "cot -w"</code></pre>
</section>


<section id="cf">
<h2>See also</h2>
<ul>
	<li><a href="settings_general.html">Change General settings in CotEditor on Mac</a></li>
</ul>
</section>

</body>
</html>
